﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using GBlason.ViewModel;
using GBlason.ViewModel.Contract;
using GBlason.ViewModel.Control;
using GBlason.ViewModel.General;

namespace GBlason.Common.TemplateSelector
{
    public class TabTemplateSelector : DataTemplateSelector
    {
        private static Dictionary<Type, DataTemplate> AvailableTypeSwitch = new Dictionary<Type, DataTemplate>();

        public override DataTemplate SelectTemplate(object item, DependencyObject container)
        {
            var typeAsKey = item.GetType();
            if (typeAsKey!=null)
            {
                if (AvailableTypeSwitch.ContainsKey(typeAsKey))
                    return AvailableTypeSwitch[typeAsKey];
            }
            return null;
        }

        public TabTemplateSelector()
        {
            if (!App.IsInDesignMode)
            {
                AvailableTypeSwitch = new Dictionary<Type, DataTemplate>
                {
                    {
                        typeof(GbsFileViewModel),
                        Application.Current.MainWindow.FindResource("CoAViewerTemplate") as DataTemplate
                    },
                    {
                        typeof(ResourceEditorViewModel),
                        Application.Current.MainWindow.FindResource("ResourceEditorItemTemplate") as DataTemplate
                    },
                    {
                        typeof(StartingPageViewModel),
                        Application.Current.MainWindow.FindResource("StartingPageTemplate") as DataTemplate
                    }
                };
            }
        }
    }
}
